<?php
namespace app\api\controller\v1;

use app\common\controller\Api;
use think\Db;
use think\Request;
use app\admin\model\Ocation;
use app\admin\model\Classes;

class ClassTeamList extends Api
{
    // 无需登录的方法，同时也就不需要鉴权了
    protected $noNeedLogin = '*';
    // 无需鉴权的方法，但需要登录
    protected $noNeedRight = '*';

    /**
     * 获取班级列表
     * @return void
     */
    public function getList()
    {
        $classList = Db::table('eb_classes')
            ->alias('c')
            ->join('eb_class_student cs', 'c.id = cs.classes_id', 'LEFT')
            ->field('c.id, c.name')
            ->group('c.id')
            ->select();

        if ($classList) {
            $this->success('获取班级列表成功', $classList);
        } else {
            $this->error('未找到班级信息');
        }
    }

    public function getLocationClass(Request $request)
    {
        $id = $request->param('id');
        $class_id = array_unique(
            Db::name('course_schedule')->where('ocation_id','in',Ocation::where('pid',$id)->column('id'))->column('classes_id')
        );
        $this->success('获取成功', Classes::where('id','in',$class_id)->field('id,name,school_id,classes_type')->select());
    }
}
